package org.redmap.controller {
	
	import flash.events.TextEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.text.engine.FontWeight;
	
	import org.redmap.model.*;
	
	public class MindMapRoundRect extends MindMapSprite {
		
		private var text:TextField;		
		private var newFormat:TextFormat = new TextFormat("ArialBold");
		public static var counter:int = -1;
		
		public function MindMapRoundRect(_id:String=null ,myWidth:Number=50, myHeight:Number=30, color:uint=0xfff000 , label:String=null) {
			
			if (_id != null){
				counter = parseInt(_id);
				this._id = _id;
			}
			else {
				_id = new Number(++counter).toString();
			}
			
			if (label != null && label.length != 0) {
				this.label = label
			} else {
				label = _id;
			}


			text = new TextField();
			text.type = TextFieldType.INPUT;
			newFormat.color = 0x000000;
			newFormat.bold = true;
            newFormat.align = TextFormatAlign.CENTER;
            text.defaultTextFormat = newFormat;
			text.alpha = 0.8;
			text.width = myWidth-10;
			text.height = myHeight-2;
			text.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);

            addChild(text);
            
            super(_id,myWidth,myHeight,radius,color,label);
            this.geometricShape = new RoundRect(width,height);
			
			 drawShape();
		}
		
		public function textInputCapture(evt:TextEvent):void{
			var str:String = text.text+evt.text;
			trace("first: "+str);
			label=str;
		}
		
		public override function drawShape():void {
			
			this.graphics.clear();
			
            text.text = label;
            //trace("label: "+label);
            //trace("text.text: "+text.text);
			
            
            this.graphics.lineStyle(1.0, this.color, 1.0);
			this.graphics.beginFill(this.color, 1.0);
            this.graphics.drawRoundRect(-1,-1,myWidth,myHeight,20);
   			
   			
    	}

	}
}